function login(username,password){
  wx.login({
  success(res) {
    if (res.code) {
      //发起网络请求
      wx.request({
        url: 'https://hongzhe.xyz/login/',
        data: {
          "username": username,
          "password": password
        },
        header: {
          'content-type': 'application/json' // 默认值
        },
        method: "POST",
        success(res) {
          if (res.statusCode == 200) {
            wx.showToast({
              title: '登录成功！',
            });
            console.log(res.data);

            wx.switchTab({
              url: "../index/index"
            });

        
            var app = getApp()
            app.globalData.username = username
            app.globalData.password = password
   
 
          } else {
            wx.showModal({
              title: "提示",
              content: "账号或密码错误!",
              showCancel: false,
              success(res) {}
            });
            wx.reLaunch({
              url: "../login/index"
            });
            
          }
        }
      })
    } else {
      console.log('登录失败！' + res.errMsg)
    }
  }
})}

Page({


  /**
   * 页面的初始数据
   */
  data: {
    name: "阿狸"
  },


  accountInput: function (e) {
    this.data.account = e.detail.value
  },


  passwordInput: function (e) {
    this.data.password = e.detail.value
  },


  regist: function (e) {

  },
  signin: function (e) {
    var that = this
    if (that.data.account == '') {
      wx.showModal({
        title: "提示",
        content: "请输入学生账号",
        showCancel: false,
        success(res) {}
      })
    } else if (that.data.password == '') {
      wx.showModal({
        title: "提示",
        content: "请输入正确的密码",
        showCancel: false,
        success(res) {}
      })
    } else {
      var username = this.data.account;
      var password = this.data.password;
      console.log("账号:" + username)
      console.log("密码:" + password)
      
      wx.showLoading({
        title: '加载中',
      })

      wx.reLaunch({
        url:"../loading/index"
      });
      setTimeout(function () {
        login(username,password);
      }, 2000)
    }
  },
// 1905080101
// 2004081339
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {


  },


  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {


  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {


  },


  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {


  },


  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {


  },


  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {


  },


  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {


  },


  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {}
})